//
//  GridView.h
//  McRemote
//
//  Created by Yuncheng Shen on 12/11/11.
//  Copyright (c) 2011 __MyCompanyName__. All rights reserved.
//

#import <UIKit/UIKit.h>

@protocol GridViewDataSource;
@protocol GridViewDelegate;

#import "GridViewCell.h"

@interface GridView : UIScrollView 

@property (nonatomic, weak) id<GridViewDelegate> gridViewDelegate;
@property (nonatomic, weak) id<GridViewDataSource> gridViewDataSource;

@property (nonatomic, readonly) CGSize cellSize;
@property (nonatomic) NSInteger pageCount;
@property (nonatomic) BOOL editing;

- (void)reloadData;

- (NSInteger)indexForCell:(GridViewCell *)cell;
- (GridViewCell *)cellAtIndex:(NSInteger)index;

/**
 index must not be greater than the count of cells array
 **/
- (BOOL)insertCell:(GridViewCell *)cell AtIndex:(NSInteger)index;
- (BOOL)deleteCellAtIndex:(NSInteger)index;

@end


#pragma mark - protocols

@protocol GridViewDataSource <NSObject>

@required
- (GridViewCell *)gridView:(GridView *)gridView cellAtIndex:(NSInteger)index;
- (NSInteger)numberOfPagesInGridView:(GridView *)gridView;

@optional
- (BOOL)gridView:(GridView *)gridView canEditCellAtIndex:(NSInteger)index;
- (void)gridView:(GridView *)gridView commitEditingStyle:(GridViewCellEditingStyle)editingStyle forCellAtIndex:(NSInteger)index;

@end


@protocol GridViewDelegate <NSObject>

@optional
- (GridViewCellEditingStyle)gridView:(GridView *)gridView editingStyleForCellAtIndex:(NSInteger)index;

- (void)gridView:(GridView *)gridView tapOnCell:(GridViewCell *)cell;
- (void)gridView:(GridView *)gridView longPressOnCell:(GridViewCell *)cell;

@end